import { Prisma } from '@prisma/client';
import { IsDefined, IsNotEmptyObject } from 'class-validator';
import { BaseDto, BaseFindDto, BaseQueryDto } from './base.dto';
import { Transform } from 'class-transformer';
import { CategoryTypeEnum } from '@/enums';

export class SPUCreateDto extends BaseDto<Prisma.SPUCreateInput> {}

export class SPUUpdateDto extends BaseDto<Prisma.SPUUpdateInput> {
  @IsDefined({ message: '条件必填' })
  @IsNotEmptyObject({ nullable: false }, { message: '条件参数必填' })
  where: Prisma.SPUWhereUniqueInput;
}

export class SPUFindDto extends BaseFindDto<
  Prisma.SPUWhereUniqueInput,
  Prisma.SPUSelect
> {}

export class SPUQueryDto extends BaseQueryDto<
  Prisma.SPUWhereUniqueInput & {
    type: CategoryTypeEnum;
  }
> {}

export class SPUListDto extends BaseQueryDto<Prisma.SPUWhereUniqueInput> {}

export class SPUOrderQueryDto extends BaseQueryDto<
  Prisma.SPUWhereUniqueInput & {
    startTime?: string;
    endTime?: string;
    total?: number;
    title?: string;
    realname?: string;
    mobile?: string;
  }
> {}

export class SPUOrderDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '密码必填' })
  pass: string;
}
